package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sc.nft.entity.vo.metaWalletDTO.AdminLinkCollectionPageVO;
import lombok.extern.slf4j.Slf4j;
import com.sc.nft.entity.CollecionLinkContrastRecords;
import com.sc.nft.mapper.CollecionLinkContrastRecordsMapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

/**
 * 关联外部藏品对照表(sc_collecion_link_contrast_records)数据DAO
 *
 * @author Sun
 * @since 2024-05-14 17:06:18
 * @description 由 Mybatisplus Code Generator 创建
 */
@Slf4j
@Repository
public class CollecionLinkContrastRecordsDao extends ServiceImpl<CollecionLinkContrastRecordsMapper, CollecionLinkContrastRecords> {

    public CollecionLinkContrastRecords getOneByCollectionId(Long collectionId) {
        LambdaQueryWrapper<CollecionLinkContrastRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollecionLinkContrastRecords::getCollectionId, collectionId);
        wrapper.orderByDesc(CollecionLinkContrastRecords::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }

    public Page<AdminLinkCollectionPageVO> getLinkCollectionPage(Page page,String collectionName,String linkCollectionName) {
        return baseMapper.getLinkCollectionPage(page,collectionName,linkCollectionName);
    }

    public boolean getIsExitByCollectionId(String linkCollectionId) {
        LambdaQueryWrapper<CollecionLinkContrastRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollecionLinkContrastRecords::getLinkCollectionId, linkCollectionId);
        return count(wrapper) > 0;
    }

    public void deleteByCollectionId(String collectionId) {
        LambdaQueryWrapper<CollecionLinkContrastRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollecionLinkContrastRecords::getCollectionId, collectionId);
        remove(wrapper);
    }

    public CollecionLinkContrastRecords getOneByLinkCollectionId(String linkCollectionId) {
        LambdaQueryWrapper<CollecionLinkContrastRecords> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(CollecionLinkContrastRecords::getLinkCollectionId, linkCollectionId);
        wrapper.orderByDesc(CollecionLinkContrastRecords::getId);
        wrapper.last("limit 1");
        return getOne(wrapper);
    }
}